<template>
  <div>
    <transition :name="transitionName">
      <router-view class="Router"></router-view>
    </transition>
    <template>
      <cube-tab-bar
        v-model="selectedLabelDefault"
        :data="tabs"
        :showSlider="false"
        @click="clickHandler"
        @change="changeHandler"
        class="banner"
      ></cube-tab-bar>
      <!-- <span class="countsum">{{countsum}}</span> -->
    </template>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
export default {
  data() {
    return {
      transitionName: "slide-right",
      selectedLabelDefault: "首页",
      tabs: [
        {
          label: "首页",
          icon: "cubeic-home"
        },
        {
          label: "计划",
          icon: "cubeic-tag"
        },
        {
          label: "我的",
          icon: "cubeic-person"
        }
      ]
    };
  },
  methods: {
    clickHandler(label) {
      // if you clicked home tab, then print 'Home'
      console.log(label);
    },
    changeHandler(label) {
      // if you clicked different tab, this methods can be emitted
      switch (label) {
        case "首页":
          this.$router.push("/botnav/index");
          break;
        case "计划":
          this.$router.push("/botnav/plan");
          break;
        case "我的":
          this.$router.push("/botnav/mine");
          break;
      }
    }
  },
  created() {
    switch (this.$route.path) {
      case "/botnav/index":
        this.selectedLabelDefault = "首页";
        break;
      case "/botnav/plan":
        this.selectedLabelDefault = "计划";
        break;
      case "/botnav/mine":
        this.selectedLabelDefault = "我的";
        break;
    }
  },
  computed: {
    ...mapGetters({
      countsum: "countsum"
    })
  }
};
</script>
<style lang="stylus" scoped>
.cube-tab-bar, .banner {
  position: fixed;
  left: 0;
  bottom: 0;
  z-index: 1000;
  width: 100%;
  background: #fff;

  /deep/ .cube-tab {
    div {
      font-size: 12px !important;
      padding-top: 3px;
    }
  }

  /deep/ i {
    font-size: 80%;
  }
}

.cube-tab-bar {
  border-top: 1px solid #eee;
}

.Router {
  position: absolute;
  width: 100%;
  transition: all 0.25s ease;
  margin-bottom: 53px;
  background-color: #ffffff;
}

.slide-left-center, .slide-right-leave-active {
  opacity: 1;
  -webkit-transform: translate(100%, 0);
  transform: translate(100%, 0);
}

.slide-right-center, .slide-left-leave-active {
  opacity: 1;
  -webkit-transform: translate(-100%, 0);
  transform: translate(-100%, 0);
}

.countsum {
  position: fixed;
  bottom: 33px;
  right: 23%;
  z-index: 1001;
  width: 18px;
  height: 18px;
  line-height: 18px;
  border-radius: 50%;
  font-size: 14px;
  background: red;
  color: #fff;
}
</style>
